Socket
Socket
Sign inDemoInstall

node-mini-migrations

Package Overview
Dependencies
4
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-mini-migrations

A very small, lightweight and flexible migrations library unconcerned with what database you use


Version published
Weekly downloads
19
decreased by-20.83%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Mini Migrations for NodeJS

Build Status David DM GitHub code size in bytes GitHub package.json version GitHub

A really simple node migrations library that is completely independant of any database or file system.

Installation

npm install --save node-mini-migrations

Example Usage

driver

const sqlite = require('sqlite-fp');
const righto = require('righto');
const up = require('node-mini-migrations/up');

function migrator (db) {
  return {
    init: (direction, callback) => {
      sqlite.run(db, 'CREATE TABLE IF NOT EXISTS _migrations (file TEXT PRIMARY KEY);', callback);
    },

    getMigrationState: (id, callback) => {
      sqlite.getOne(db, 'SELECT file FROM _migrations WHERE file = ?', [id], callback);
    },

    setMigrationUp: (id, callback) => {
      sqlite.run(db, 'INSERT INTO _migrations (file) VALUES (?)', [id], callback);
    },

    setMigrationDown: (id, callback) => {
      sqlite.run(db, 'DELETE FROM _migrations WHERE file = ?', [id], callback);
    },

    handler: (fn, callback) => fn(db, callback)
  };
};

const db = righto(sqlite.connect, './test.sqlite');
const driver = righto.sync(migrator, db);
const migrations = getMigrationsFromDirectory('./test/migrations');
const migrated = righto(up, driver, migrations);
migrated(callback)

migration

module.exports = {
  up: db => {
    return db.exec('CREATE TABLE test_table (test TEXT)')
  },

  down: db => {
    return db.exec('DROP TABLE test_table')
  }
}

License

This project is licensed under the terms of the MIT license.

FAQs

Last updated on 26 Apr 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc